Application_End() cannot access cache through HttpContext.Current.Cache[key]

Posted by Carl J. on Stack Overflow See other posts from Stack Overflow or by Carl J.
Published on 2010-12-12T01:37:40Z Indexed on 2011/01/05 14:54 UTC
Read the original article Hit count: 273

I want to be able to maintain certain objects between application restarts.

To do that, I want to write specific cached items out to disk in Global.asax Application_End() function and re-load them back on Application_Start().

I currently have a cache helper class, which uses the following method to return the cached value:

return HttpContext.Current.Cache[key];

Problem: during Application_End(), HttpContext.Current is null since there is no web request (it's an automated cleanup procedure) - therefore, I cannot access .Cache[] to retrieve any of the items to save to disk.

Question: how can I access the cache items during Application_End()?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET